<?php
include_once '../Login/databaseconnection.php';
$Res_Id=$_SESSION['Resource_Id'];
$Ser_Number=$_SESSION['Serial_Number'];
$_SESSION['Se_Number']=$_SESSION['Serial_Number'];
$_SESSION['Res_Id']=$_SESSION['Resource_Id'];
$Resource_Id=$_POST['Resource_Id'];
$Lab_Id=$_POST['Lab_Id'];
   $Serial_Number=$_POST['Serial_Number'];
 $Functioning=$_POST['Functioning'];
    $Brand_Name=$_POST['Brand_Name'];
    $Date_Of_Supplied=$_POST['Date_Of_Supplied'];
    $Name_Of_Supplier=$_POST['Name_Of_Supplier'];
    $Funding_Source=$_POST['Funding_Source'];
	$School_Id=$_POST['School_Id'];
	date_default_timezone_set("Europe/Paris");
    $t_d=date("Y/m/d");
   
   $pervious=mysql_query("SELECT * FROM resource_details WHERE  Resource_Id='$Res_Id' AND Serial_Number='$Ser_Number''");
	if($pervious)
	{
	if($per_row=mysql_fetch_array($pervious))
	{
	$Date_Of_Suppliedp=$per_row['Date_Of_Supplied'];
   $Name_Of_Supplierp=$per_row['Name_Of_Supplier'];
   $Funding_Sourcep=$per_row['Funding_Source'];
	}
	}
   if($Resource_Id==""||$Lab_Id==""||$Serial_Number==""||$Functioning==""||$Brand_Name==""||$School_Id=="")
	{
		   $_SESSION['errorin']="Please check your inputs!";	 
	}
	else
	{
	 if(($Date_Of_Suppliedp!=""&&$Date_Of_Supplied=="")||($Name_Of_Supplierp!=""&&$Name_Of_Supplier=="")||($Funding_Sourcep!=""&&$Funding_Source==""))
  {
   $_SESSION['errorempt']="You have delete some values If you want to put them,Please update again!";
  }
$sql=mysql_query("UPDATE resource_details SET Resource_Id='$Resource_Id',Lab_Id='$Lab_Id',Serial_Number='$Serial_Number',Functioning='$Functioning',Brand_Name='$Brand_Name',Date_Of_Supplied='$Date_Of_Supplied',Name_Of_Supplier='$Name_Of_Supplier',Funding_Source='$Funding_Source',School_Id='$School_Id',Last_Updated_Date='$t_d' WHERE Resource_Id='$Res_Id' AND Serial_Number='$Ser_Number'");
unset($_SESSION['Resource_Id']);
unset($_SESSION['Serial_Number']);
if(mysql_affected_rows()!=0)
  {
$_SESSION['error']="This record is successfully updated!";
  }
  if((mysql_affected_rows()==0)||!$sql)
  {
 $_SESSION['error']="Sorry unable to update this record!";
  }
	
}
  ?>
